﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Leadtools;
using Leadtools.Codecs;
using Leadtools.WinForms;
using MINERP.BLL.PhotoRindGrid;
using MINERP.COM;
using MINERP.ComControls;
using MINERP.MODEL.FoundationModel;
using MINERP.MODEL.OverOrder;
using MINERP.PhotoRindGrid.IView;
using MINERP.PhotoRindGrid.Forms;

namespace MINERP.PhotoRindGrid
{
    public partial class FrmPhotoRindGrid : FrmParent, IFrmPhotoRindGrid
    {
        public FrmPhotoRindGrid()
        {
            InitializeComponent();
            base.InitiAuthority();

        }

        private StringBuilder strBPhotoBarCode = new StringBuilder("");
        private Presenter.MainPresenter _presenter;
        private int _userid = 0;


        private void txtBoxPhotoBarCode_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.KeyCode == Keys.Enter)
                {
                    string strPhBarcode = txtBoxPhotoBarCode.Text.Trim();
                    if (strPhBarcode.Length < 10)
                    {
                        string strZero = "";
                        for (int i = 0; i < 9 - strPhBarcode.Length; i++)
                        {
                            strZero += "0";
                        }
                        strPhBarcode = "3" + strZero + strPhBarcode;
                    }
                    CurrBarCode = strPhBarcode;
                    txtBoxPhotoBarCode.Text = CurrBarCode;
                    if (strPhBarcode.Length != 10)
                    {
                        MessageBox.Show("您输入的条码有误，请重新输入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        this.txtBoxPhotoBarCode.Clear();
                        return;
                    }
                    else
                    {
                        this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
                        //InputPhoto(strPhBarcode);

                        _presenter.ReceiveBarCode();

                        txtBoxPhotoBarCode.Text = "";
                        this.CurrBarCode = "";
                        this.Cursor = System.Windows.Forms.Cursors.Default;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }

        private void txtBoxPhotoBarCode_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((int)e.KeyChar <= 31)//功能按键
            {
                return;
            }

            if (!char.IsDigit(e.KeyChar))
            {
                e.Handled = true;
                return;
            }
        }

        private void txtBoxPhotoBarCode_Enter(object sender, EventArgs e)
        {
            this.KeyPreview = false;
        }

        private void txtBoxPhotoBarCode_Leave(object sender, EventArgs e)
        {
            this.KeyPreview = true;
        }

        private void FrmPhotoRindGrid_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (char.IsDigit(e.KeyChar))
            {
                if (strBPhotoBarCode.Length >= 10)
                {
                    e.Handled = true;
                }
                else
                {
                    strBPhotoBarCode.Append(e.KeyChar);
                }

                txtBoxPhotoBarCode.Text = strBPhotoBarCode.ToString();


            }
            else if (e.KeyChar == (char)27)//如果按的是ESC键
            {
                if (this.splitContainerControlbottom.PanelVisibility != SplitPanelVisibility.Panel1)
                {
                    this.splitContainerControlbottom.PanelVisibility = SplitPanelVisibility.Panel1;
                    //_presenter.ShowAllGrid();
                    if (CurrPhotoList!=null)
                    {
                        CurrPhotoList.Clear();
                    }
                    this.CurrentGrid = CurrentGrid;
                }
            }


            else if (e.KeyChar == (char)13)//用户输入回车键
            {
                string strBarCode = txtBoxPhotoBarCode.Text.Trim();
                //if (strBPhotoBarCode.ToString().Length != 10)
                if (strBarCode.Length < 10)
                {
                    string strZero = "";
                    for (int i = 0; i < 9 - strBarCode.Length; i++)
                    {
                        strZero += "0";
                    }
                    strBarCode = "3" + strZero + strBarCode;
                }
                if (strBarCode.Length != 10)
                {
                    MessageBox.Show("照片条码长度不为10位，请重新输入！" + strBarCode.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    strBPhotoBarCode = new StringBuilder();
                }
                else
                {
                    this.CurrBarCode = strBarCode.ToString();
                    this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
                    _presenter.ReceiveBarCode();
                    CurrBarCode = "";
                    strBPhotoBarCode = new StringBuilder();
                    txtBoxPhotoBarCode.Text = "";
                    strBarCode = "";
                    this.Cursor = System.Windows.Forms.Cursors.Default;
                }
            }
            else if ((int)e.KeyChar <= 31)
            {
                return;

            }
        }

        private void FrmPhotoRindGrid_Load(object sender, EventArgs e)
        {


            _curTechId = base.CurrentTechID;
            //OperateUserId = base.userId;
            _userid = base.userId; ;
            lblCurrentUser.Text = "当前操作员：" + base.userName;
            _presenter = new MINERP.PhotoRindGrid.Presenter.MainPresenter(this);
            // FrmSelectSubarea frm = new FrmSelectSubarea();
            try
            {
                _presenter.BingSubAreas();
            }
            catch (Exception)
            {
                MessageBox.Show("当前没有可用分区", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Exit();
                return;
            }

            _presenter.ShowAllGrid();
            this.Text = "分片 当前分区：" + this.CurrSubares.SubAreaName;

        }

        public int OperateUserId
        {
            get { return _userid; }
            set { _userid = value; }
        }

        public UCGrid CurrGrid
        {
            //get { return _currGrid; } 
            //set
            //{
            //    if(string.IsNullOrEmpty(value.ShopName))
            //    {
            //        this.toolStripButton5.Enabled = false;
            //    }
            //    else
            //    {
            //        this.toolStripButton5.Enabled = true;

            //    }
            //}
            set;
            get;
        }
        public List<PhotoView> CurrPhotoList
        {
            set;
            get;
        }
        //private UCGrid _currGrid;
        private int _curTechId = 8;
        public int CurrTech
        {
            set { ;}
            get { return _curTechId; }//基类中获得
            //get { return 7; }
        }

        public string CurrBarCode
        {
            get;
            set;

        }

        public string ProductBarCode
        {
            get;
            set;
        }

        public Hashtable gridHash
        {
            get;
            set;
        }

        public GridSubArea_Info CurrSubares
        {
            get;
            set;
        }

        public Grid_Info CurrentGrid
        {
            get;
            set;
        }

        public List<PhotoSubarea_Info> SubAreas
        {
            get;
            set;
        }
        
        public void ShowGrid(List<GridView> listGrid)
        {
            gridHash = new Hashtable();
            tableLayoutPanelGrid.Controls.Clear();
            tableLayoutPanelGrid.ColumnStyles.Clear();
            tableLayoutPanelGrid.RowStyles.Clear();
            //tableLayoutPanelGrid.RowCount = CurrSubares.WidthNum;

            //tableLayoutPanelGrid.ColumnCount = CurrSubares.HeightNum;
            tableLayoutPanelGrid.RowCount = CurrSubares.HeightNum;

            tableLayoutPanelGrid.ColumnCount = CurrSubares.WidthNum;
            int panelWigth = 0;
            if (splitContainerControlbottom.Panel2.Visible == false)
            {
                panelWigth = splitContainerControlbottom.Width;
            }
            else
            {
                panelWigth = splitContainerControlbottom.Panel1.Width;
            }


            int panelHight = splitContainerControlbottom.Panel1.Height;

            int GZwidth = (panelWigth - (CurrSubares.WidthNum - 1) * 7) / CurrSubares.WidthNum;//格子的宽
            int ZGheight = (panelHight - (CurrSubares.HeightNum - 1) * 7) / CurrSubares.HeightNum;//格子的高
            UCGrid ucGrid;
            foreach (GridView view in listGrid)
            {
                ucGrid = new UCGrid();
                ucGrid.Width = GZwidth;
                ucGrid.Height = ZGheight;

                ucGrid.GridId = view.GridId;
                ucGrid.GridName = view.GridName;

                if (ucGrid.CompleteTime.CompareTo(Convert.ToDateTime("2000-01-01")) <= 0)
                {
                    ucGrid.CompleteTime = Convert.ToDateTime("2000-01-01");
                }
                ucGrid.FirstEnterTime = view.FristEnterTime;
                //ucGrid.Click += new EventHandler(ucGrid_Click);
                //ucGrid.DoubleClick += new EventHandler(ucGrid_DoubleClick);
                ucGrid.UCGridClick += new UCGrid.PostClicks(ucGrid_Click);
                ucGrid.UCGridDoubleClick += new UCGrid.PostClicks(ucGrid_DoubleClick);
                ucGrid.BackColor = Color.White;
                if (view.OrderProductInfo != null)
                {
                    ucGrid.OrderId = view.OrderProductInfo.OrderProductId;
                    ucGrid.labProductName.Text = view.OrderProductInfo.OrderProductName;
                    ucGrid.ShopName = view.ShopName;
                    ucGrid.labCurr.Text = view.Curr.ToString();
                    ucGrid.labCout.Text = @"/" + view.Count;
                    if ((DateTime.Now - ucGrid.FirstEnterTime).TotalHours > this.CurrSubares.OutTimeAlarmTime)
                    {
                        ucGrid.BackColor = Color.Red;
                    }
                }

                //if (view.OrderBagName != null && !(view.OrderBagName.Equals("")))
                //{
                //    //ucGrid.ShopId = view.ShopInfo.ShopId;
                //    //ucGrid.labOrderName.Text = "定单名称:"+view.OrderBagName;
                //    //ucGrid.labOrderName.Text = "定单条码:" + view.OrderProductInfo.OrderProductCode;
                //    //ucGrid.labProductName.Text = "产品名称:" + view.ProductName;
                //    //ucGrid.OrderId = view.ProductId;
                //    ucGrid.labCurr.Text =  view.Curr.ToString();
                //    ucGrid.labCout.Text = @"/" + view.Count;
                //    //ucGrid.labShopName.Text = "商户名称:" + view.ShopName;

                //    if ((DateTime.Now - ucGrid.FirstEnterTime).TotalMinutes > this.CurrSubares.OutTimeAlarmTime)
                //    {
                //        ucGrid.BackColor = Color.Red;
                //    }

                //}
                tableLayoutPanelGrid.Controls.Add(ucGrid);
                gridHash.Add(ucGrid.GridId, ucGrid);


            }
        }

        //public void SetEvent(Control control)
        //{
        //    control.Click += new EventHandler(ucGrid_Click);
        //    control.DoubleClick += new EventHandler(ucGrid_DoubleClick);
        //    ControlCollection ccl = (ControlCollection)control.Controls;
        //    foreach (Control collection in ccl)
        //    {
        //        SetEvent(collection);
        //    }

        //}
        void ucGrid_DoubleClick(UCGrid grid)
        {
            _presenter.SetSelectGridStyle(grid, CurrGrid);
            //this.CurrentGrid = _presenter.GetGridById(grid.GridId);
            this.CurrGrid = grid;
            //this.ClearGridInfo();
            ///取得商户和照片信息
            //if (CurrentGrid.SomeId != 0)
            if (grid.OrderId != 0)
            {
                this.toolStripButton5.Enabled = true;
                btnPrint.Enabled = true;
                _presenter.DisplayShopInfo();
                this.splitContainerControlbottom.PanelVisibility = SplitPanelVisibility.Both;
            }
            else
            {
                this.toolStripButton5.Enabled = false;
                btnPrint.Enabled = false;
            }
        }

        //void ucGrid_DoubleClick(object sender, EventArgs e)
        //{
        //    UCGrid grid = (UCGrid)sender;
        //    _presenter.SetSelectGridStyle(grid, CurrGrid);
        //    this.CurrentGrid = _presenter.GetGridById(grid.GridId);
        //    this.CurrGrid = grid;
        //    this.ClearGridInfo();
        //    ///取得商户和照片信息
        //    if (CurrentGrid.SomeId != 0)
        //    {
        //        this.toolStripButton5.Enabled = true;
        //        btnPrint.Enabled = true;
        //        _presenter.DisplayShopInfo();
        //        this.splitContainerControlbottom.PanelVisibility = SplitPanelVisibility.Both;
        //    }
        //    else
        //    {
        //        this.toolStripButton5.Enabled = false;
        //        btnPrint.Enabled = false;
        //    }


        //}

        void ucGrid_Click(UCGrid grid)
        {     
            _presenter.SetSelectGridStyle(grid, CurrGrid);
            this.CurrentGrid = _presenter.GetGridById(grid.GridId);
            this.CurrGrid = grid;

            if (CurrGrid.OrderId != 0)
            {
                if (this.splitContainerControlbottom.PanelVisibility == SplitPanelVisibility.Both)
                {
                    //this.ClearGridInfo();
                    _presenter.DisplayShopInfo();
                }

                this.toolStripButton5.Enabled = true;
                btnPrint.Enabled = true;
                //if (CurrGrid != null && CurrGrid.Curr != " " && CurrGrid.Curr.Split(':')[1] != "0" && CurrGrid.Curr.Split(':')[1] == CurrGrid.Cout.Split(':')[1])
                //{
                //    CurrGrid.ContextMenuStrip = this.contextMenuStrip_Print;
                //}
            }
            else
            {
                this.toolStripButton5.Enabled = false;
                btnPrint.Enabled = false;
            }
        }

        /// <summary>
        /// 单击格子
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //void ucGrid_Click(object sender, EventArgs e)
        //{
        //    UCGrid grid = (UCGrid) sender;
        //    _presenter.SetSelectGridStyle(grid, CurrGrid);
        //    this.CurrentGrid = _presenter.GetGridById(grid.GridId);
        //    this.CurrGrid = grid;
        //    this.ClearGridInfo();
        //    if (CurrentGrid.SomeId != 0)
        //    {
        //        //_presenter.DisplayShopInfo();
        //        this.toolStripButton5.Enabled = true;
        //        btnPrint.Enabled = true;
        //        if (CurrGrid != null && CurrGrid.Curr != " " && CurrGrid.Curr.Split(':')[1] != "0" && CurrGrid.Curr.Split(':')[1] == CurrGrid.Cout.Split(':')[1])
        //        {
        //            CurrGrid.ContextMenuStrip = this.contextMenuStrip_Print;
        //        }
        //    }
        //    else
        //    {
        //        this.toolStripButton5.Enabled = false;
        //        btnPrint.Enabled = false;
        //    }


        //}

        public void ShowPhotoByGrid(List<PhotoView> listphoto)
        {
            this.gridControlPhoto.DataSource = null;
            this.gridControlPhoto.DataSource = listphoto;
            lblPhotoCount.Text = listphoto.Count.ToString();
            lblPhotoCurrentCount.Text = listphoto.Where(pv => pv.Status == 4).Count().ToString();
        }

        public void ShowPhotoImage(List<PhotoView> listphoto)
        {
            rasterThumbnailBrowserImageList.Items.Clear();
            foreach (PhotoView view in listphoto)
            {
                if (view.Status != (int)(PhotoStatus.FenPian))
                {


                    try
                    {
                        RasterCodecs.Startup();
                        RasterCodecs codecs = new RasterCodecs();
                        CodecsThumbnailOptions options = new CodecsThumbnailOptions();
                        options.Resample = true;
                        options.LoadStamp = true;
                        options.MaintainAspectRatio = true;
                        RasterImage img;
                        try
                        {
                            img = codecs.ReadThumbnail(view.PicPath, options, 1);
                        }
                        catch
                        {
                            //为图片设置Stamp
                            RasterImage imgInfo = codecs.Load(view.PicPath);
                            Rectangle rc = RasterImage.CalculatePaintModeRectangle(imgInfo.Width, imgInfo.Height,
                                                                                   new Rectangle(0, 0, 128, 128),
                                                                                   RasterPaintSizeMode.FitAlways,
                                                                                   RasterPaintAlignMode.Near,
                                                                                   RasterPaintAlignMode.Near);
                            codecs.Options.Jpeg.Save.StampWidth = rc.Width;
                            codecs.Options.Jpeg.Save.StampHeight = rc.Height;
                            codecs.Options.Jpeg.Save.SaveWithStamp = true;
                            codecs.Options.Jpeg.Save.StampBitsPerPixel = 24;
                            codecs.Save(imgInfo, view.PicPath, RasterImageFormat.Jpeg, 0);
                            //重新读缩略图
                            img = codecs.ReadThumbnail(view.PicPath, options, 1);
                        }
                        int index = view.PicPath.LastIndexOf("\\");
                        string fileName = view.PicPath.Substring(index + 1);
                        RasterImageListItem item = new RasterImageListItem(img, 1, fileName);
                        item.Tag = view.PicPath;
                        rasterThumbnailBrowserImageList.Items.Add(item);

                    }
                    catch
                    {
                        return;
                    }
                }
            }
        }

        public void RushGrid(GridView view)
        {

            ((UCGrid)gridHash[view.GridId]).labOrderName.Text = "定单名称:" + view.OrderBagName;
            ((UCGrid)gridHash[view.GridId]).labProductName.Text = "产品名称:" + view.ProductName;
            ((UCGrid)gridHash[view.GridId]).labShopName.Text = "商户名称:" + view.SubName;
            ((UCGrid)gridHash[view.GridId]).labCurr.Text = "已分配数量:" + view.Curr.ToString();
            ((UCGrid)gridHash[view.GridId]).labCout.Text = "总数量:" + view.Count.ToString();


        }

        public void ClearGrid()
        {
            //_presenter.ClearGrid();
            this.ClearGridInfo();
            if (CurrentGrid != null)
            {

                ((UCGrid)gridHash[CurrentGrid.GridId]).labProductName.Text = "";

                //((UCGrid) gridHash[CurrentGrid.GridId]).labOrderName.Text = "定单名称:";
                //((UCGrid) gridHash[CurrentGrid.GridId]).labProductName.Text = "产品名称:";
                //((UCGrid) gridHash[CurrentGrid.GridId]).labShopName.Text = "商户名称:";
                //((UCGrid) gridHash[CurrentGrid.GridId]).labCurr.Text = "已分配数量:";
                //((UCGrid) gridHash[CurrentGrid.GridId]).labCout.Text = "总数量:";
                //((UCGrid) gridHash[CurrentGrid.GridId]).CompleteTime = Convert.ToDateTime("2000-01-01");
            }
        }



        public void SelectSubArea(List<GridSubArea_Info> subAreaList)
        {
            FrmSelectSubarea frm = new FrmSelectSubarea();
            frm.listSubarea = subAreaList;
            if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.CurrSubares =
                    _presenter.GetOneSuAreaById(Convert.ToInt32(frm.comboBox_SelectSubarea.SelectedValue));
            }
            else
            {
                Exit();
            }
        }

        public void Exit()
        {
            this.Close();
            MINERP.COM.Logoff.ShowMainFrm();
        }

        public void ShowGridInfo(List<GridView> view)
        {
            foreach (GridView list in view)
            {
                this.lblOrderBarCode.Text = list.BagCode;
                this.lblOrderName.Text = list.OrderBagName;
                this.lblShopName.Text = list.ShopName;
                this.lblCtmName.Text = list.CustomerName;
                this.lblGridName.Text = list.GridName;
                this.lblSubareaName.Text = list.SubName;
                this.lblPhotoCount.Text = list.Count.ToString();
                this.lblPhotoCurrentCount.Text = list.Curr.ToString();
            }
        }

        public void ShowGridInfo(MINERP.MODEL.PhotoRindGrid.PhotoGridOrderHeadInfo photoGridOrderHeadInfo)
        {
            this.lblOrderBarCode.Text = photoGridOrderHeadInfo.orderBagCode;
            this.lblOrderName.Text = photoGridOrderHeadInfo.orderInfoCode;
            this.lblShopName.Text = photoGridOrderHeadInfo.shopName;
            this.lblCtmName.Text = photoGridOrderHeadInfo.ctmName;
            this.lblGridName.Text = photoGridOrderHeadInfo.GridName;
            this.lblSubareaName.Text = photoGridOrderHeadInfo.orderProductName;
            //this.lblPhotoCount.Text = photoGridOrderHeadInfo.Count.ToString();
            //this.lblPhotoCurrentCount.Text = photoGridOrderHeadInfo.Curr.ToString();
        }
        /// <summary>
        /// 清空右边的详细信息
        /// </summary>
        private void ClearGridInfo()
        {
            if (splitContainerControlbottom.PanelVisibility == SplitPanelVisibility.Both)
            {
                this.lblOrderBarCode.Text = "";
                this.lblOrderName.Text = "";
                this.lblShopName.Text = "";
                this.lblCtmName.Text = "";
                this.lblGridName.Text = "";
                this.lblSubareaName.Text = "";
                this.lblPhotoCount.Text = "";
                this.lblPhotoCurrentCount.Text = "";
                this.gridControlPhoto.DataSource = null;
            }


        }



        private void toolStripButton5_Click_1(object sender, EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            _presenter.ClearGrid();
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void tsbtnLogout_Click(object sender, EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            _presenter.BingSubAreas();
            _presenter.ShowAllGrid();
            this.Text = "分片 当前分区：" + this.CurrSubares.SubAreaName;
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            _presenter.ChangeAreasUsed();
            this.Exit();
        }

        private void FrmPhotoRindGrid_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (CurrSubares != null)
            {
                _presenter.ChangeAreasUsed();
            }

            MINERP.COM.Logoff.ShowMainFrm();
        }

        private void gridViewphoto_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
        {

        }

        private void gridViewphoto_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            int rowNum = e.RowHandle;
            PhotoView viewRow = (PhotoView)gridViewphoto.GetRow(rowNum);
            if (viewRow.Status == (int)PhotoStatus.FenPian)
            {
                e.Appearance.BackColor = Color.LightSkyBlue;
            }
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            string strPhBarcode = txtBoxPhotoBarCode.Text.Trim();
            CurrBarCode = txtBoxPhotoBarCode.Text.Trim();
            if (strPhBarcode.Length != 10)
            {
                MessageBox.Show("您输入的条码有误，请重新输入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                this.txtBoxPhotoBarCode.Clear();
                return;
            }
            else
            {
                this.Cursor = Cursors.WaitCursor;
                //InputPhoto(strPhBarcode);
                _presenter.ReceiveBarCode();
                // _presenter.Assion();

                //txtBoxPhotoBarCode.Text = "";
                txtBoxPhotoBarCode.Clear();
                this.Cursor = Cursors.Default;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {

        }

        private void timerCheck_Tick(object sender, EventArgs e)
        {
            //foreach (DictionaryEntry item in gridHash)
            //{
            //   if((DateTime.Now-((UCGrid)(item.Value)).FirstEnterTime).TotalMinutes>CurrSubares.OutTimeAlarmTime)
            //   {
            //       ((UCGrid) (item.Value)).BackColor = Color.Red;
            //       //MessageBox.Show(((UCGrid) (item.Value)).GridName + "号格子已超时", "提示", MessageBoxButtons.OK,
            //       //                MessageBoxIcon.Information);
            //   }
            //    if((DateTime.Now-((UCGrid)(item.Value)).CompleteTime).TotalMinutes>CurrSubares.GridClearTime)
            //    {
            //        ((UCGrid)item.Value).labOrderName.Text = "定单名称:" ;
            //        ((UCGrid)item.Value).labProductName.Text = "产品名称:";
            //        ((UCGrid)item.Value).labShopName.Text = "商户名称:" ;
            //        ((UCGrid)item.Value).labCurr.Text = "已分配数量:" ;
            //        ((UCGrid)item.Value).labCout.Text = "总数量:";
            //    }
            //}

        }

        private void toolStripSeparator5_Click(object sender, EventArgs e)
        {

        }

        private void tsBtn_Seach_Click(object sender, EventArgs e)
        {
            List<string> shopNameList = new List<string>();
            foreach (DictionaryEntry item in gridHash)
            {
                if (((UCGrid)item.Value).BackColor == Color.Pink)
                {
                    ((UCGrid)item.Value).BackColor = Color.White;
                }
                string shopName = ((UCGrid)item.Value).ShopName;
                if (shopName == null)
                {
                    continue;
                }

                string shopOutName = shopNameList.Find(delegate(string b)
                {
                    if (b.Equals(shopName))
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                });
                if (shopOutName == null)
                {
                    shopNameList.Add(shopName);
                }

            }
            FrmSearch frm = new FrmSearch(shopNameList);
            frm.SendGridColor += new FrmSearch.SendSearch(frm_SendGridColor);
            frm.ShowDialog();
        }

        void frm_SendGridColor(int shopId, string inShopName)
        {
            if (inShopName != "")
            {

                foreach (DictionaryEntry item in gridHash)
                {
                    string shopName = ((UCGrid)item.Value).ShopName;
                    if (!string.IsNullOrEmpty(shopName))
                    {

                        if (inShopName == shopName)
                        {
                            // ((UCGrid)item.Value).
                            ((UCGrid)(item.Value)).BackColor = Color.Pink;
                        }
                    }
                }
            }
        }

        private void gridViewphoto_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            if (e.Column.FieldName == "Status")
            {
                int status =

                    Convert.ToInt32(
                        ((PhotoView)(gridViewphoto.GetRow(e.RowHandle))).Status);
                switch (status)
                {
                    case (int)PhotoStatus.NoDistributePrinter:
                        {

                            e.DisplayText = "未分配打印机";
                        }
                        break;
                    case (int)PhotoStatus.DistributedPrinter:
                        {

                            e.DisplayText = "等待打印";
                        }
                        break;
                    case (int)PhotoStatus.PingBan:
                        {

                            e.DisplayText = "已拼版,未打印";
                        }
                        break;
                    case (int)PhotoStatus.Printed:
                        {
                            e.DisplayText = "等待分片";
                        }
                        break;
                    case (int)PhotoStatus.FenPian:
                        {
                            e.DisplayText = "分片完成";
                        }
                        break;
                    case (int)PhotoStatus.PhotoInnerReturn:
                        {
                            e.DisplayText = "照片返单中";
                        }
                        break;
                    case (int)PhotoStatus.PingBanInd:
                        {
                            e.DisplayText = "拼版中";
                        }
                        break;
                    case (int)PhotoStatus.WaitPhotoMove:
                        {
                            e.DisplayText = "照片等待移动";
                        }
                        break;
                    case (int)PhotoStatus.PhotoNotExist:
                        {
                            e.DisplayText = "照片不存在";
                        }
                        break;

                    default:
                        break;
                }
            }
        }

        private void gridControlPhoto_Click(object sender, EventArgs e)
        {

        }



        private void contextMenuStrip_Print_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            contextMenuStrip_Print.Close();
            _presenter.PrintGrid();

        }

        private void splitContainerControlbottom_Paint(object sender, PaintEventArgs e)
        {
            if (this.SubAreas == null)
            {

            }
            else
            {
                _presenter.ShowAllGrid();

            }
        }

        private void txtBoxPhotoBarCode_Click(object sender, EventArgs e)
        {

        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            if (DialogResult.OK == MessageBox.Show("该产品未分片未完成，确认打印吗？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
            {
                _presenter.PrePrint();
            }

        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if (splitContainerImageAndList.Panel1Collapsed == true)
            {
                splitContainerImageAndList.Panel1Collapsed = false;
                splitContainerImageAndList.Panel2Collapsed = true;
            }
            else
            {
                splitContainerImageAndList.Panel1Collapsed = true;
                splitContainerImageAndList.Panel2Collapsed = false;
            }
            if (this.CurrentGrid.SomeId != null || CurrentGrid.SomeId != 0)
            {
                if (splitContainerImageAndList.Panel1.Visible == true)
                {
                    _presenter.DisplayShopInfoIamge();
                }

            }
        }





        #region IFrmPhotoRindGrid 成员
        string str1,str2,str3,str4, strtemp;

        public void DisPlayGriName(string Name)
        {
            strtemp = str2;
            str2 = str1;
            str1 = Name;

            str4 = str3;
            str3 = strtemp;

            this.toolStripLabelGridNum.Text = str1;
            //lbl2.Text = str2;
            //lbl3.Text = str3;
            //lbl4.Text = str4;
        }

        #endregion

        private void tsbAdvance_Click(object sender, EventArgs e)
        {
            try
            {
                FrmPhotoNum frm = new FrmPhotoNum();
                if (DialogResult.OK == frm.ShowDialog())
                {
                    int num = Convert.ToInt32(frm.spinEditNum.Text);

                    if (num == 0)
                    {
                        if (System.Windows.Forms.DialogResult.OK == MessageBox.Show("确定要加急所有格子中照片的大板的加急级别吗？这个过程可能要几分钟，请耐心等待...", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                        {
                            this.Cursor = Cursors.WaitCursor;
                            _presenter.AdvanceBoard(num);
                            this.Cursor = Cursors.Default;
                        }
                    }
                    else
                    {
                        if (System.Windows.Forms.DialogResult.OK == MessageBox.Show("确定要加急格子中照片所剩余数量少于" + num + "的大板的加急级别吗？这个过程可能要几分钟，请耐心等待...", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                        {
                            this.Cursor = Cursors.WaitCursor;
                            _presenter.AdvanceBoard(num);
                            this.Cursor = Cursors.Default;
                        }
                    }
                    MessageBox.Show("清柜已完成！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            finally
            {

            }


        }

        private void tsbAdvanceProduct_Click(object sender, EventArgs e)
        {
            try
            {
                if (System.Windows.Forms.DialogResult.OK == MessageBox.Show("确定要加急选中格子中的产品吗？这个过程可能要几分钟，请耐心等待...", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                {

                    string strProductid = "";
                    foreach (DictionaryEntry item in gridHash)
                    {
                        int orderid = ((UCGrid)item.Value).OrderId;
                        if (orderid != null && orderid != 0 && ((UCGrid)item.Value).BackColor == Color.Pink)
                        {
                            strProductid += orderid.ToString() + ",";
                        }
                    }
                    strProductid = strProductid.TrimEnd(',');
                    if (strProductid != "")
                    {
                        this.Cursor = Cursors.WaitCursor;
                        _presenter.AdvanceGrid(strProductid);
                        this.Cursor = Cursors.Default;
                    }
                    else
                    {
                        MessageBox.Show("您选择的格子为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    MessageBox.Show("选中格子清柜已完成！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            finally
            {
                this.Cursor = Cursors.Default;
            }


        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            ComControls.frmMain.GetInstance(base.userId);

        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            FrmReCheck frm = new FrmReCheck();
            frm.ShowDialog();
        }

        private void buttonCreateFan_Click(object sender, EventArgs e)
        {
            List<PhotoView> CurrListPhoto = new List<PhotoView>();
            if (CurrPhotoList==null||CurrPhotoList.Count<1)
            {
                MessageBox.Show("请双击选中某一格子后再返单！");
                return;
            }
            CurrListPhoto=CurrPhotoList.Where(p => p.Status != (int)PhotoStatus.FenPian).ToList();
            List<MINERP.BLL.InnerReturn.PhotoView> listView = new List<MINERP.BLL.InnerReturn.PhotoView>();
            foreach (PhotoView view in CurrListPhoto)
            {
                MINERP.BLL.InnerReturn.PhotoView newView = new MINERP.BLL.InnerReturn.PhotoView();
                newView.Photo= view.PhotoInfo;
                listView.Add(newView);
            }

            FrmFanDan frm = new FrmFanDan(listView, this.OperateUserId, this.CurrentTechID, this.CurrGrid.GridId);
            frm.Show();

        }











        #region IFrmPhotoRindGrid 成员




        #endregion
    }
}
